package com.threeti.jiayusms.domain.service.communicationfunction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.threeti.jiayusms.domain.model.CommunicationFunction;
import com.threeti.jiayusms.framework.util.DynaSearchCriteria;
import com.threeti.jiayusms.framework.util.PagedListHandler;
import com.threeti.jiayusms.infrastructure.communicationfunction.CommunicationFunctionDao;

@Service
@Transactional(readOnly=true)
public class CommunicationFunctionQueryServiceImpl implements
		CommunicationFunctionQueryService {

	@Autowired
	private CommunicationFunctionDao dao;

	@Override
	public CommunicationFunction findCommunicationFunctionBy(Long functionId) {
		return dao.loadBy(functionId, true);
	}
	
	@Override
	public CommunicationFunction findCommunicationFunctionBy(String functionNo) {
		return dao.loadBy(functionNo);
	}
	
	@Override
	public PagedListHandler<CommunicationFunction> findAllFunctionTemplatesByPage(int currentPageIndex, int startingIndex) {
    return dao.findAllFunctionTemplatesByPage(currentPageIndex, startingIndex);
	}

	@Override
	public PagedListHandler<CommunicationFunction> findFunctionTemplatesByPage(DynaSearchCriteria dynaSearchCriteria, int currentPageIndex, int startingIndex) {
		if (!dynaSearchCriteria.isAnyConditionInput()) {//无条件查询
			return dao.findAllFunctionTemplatesByPage(currentPageIndex, startingIndex);
		}
    return dao.findFunctionTemplatesByPage(dynaSearchCriteria, currentPageIndex, startingIndex);
	}
}
